<template>
	<view class="body">
		<infomationVue :query="query"></infomationVue>
		<view class="tabs">
			<view class="Item" v-for="(item,index) in tabslist" :key="index" @click.stop="changeIndex(index)">
				<text class="size" :style="{color:activeIndex == index ?'#73F0EA':'#666666'}">{{item}}</text>
				<view class="bar" :style="{background:activeIndex == index ?'#73F0EA':''}">

				</view>
			</view>
		</view>
		<scroll-view scroll-y="true" class="scroll-y"  @scrolltolower="scrolltolower">
			<view class="comlum_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="Item">
					<view class="header">
						<image :src="$IMG_URL('/static/user/logo1.png')" mode="aspectFill" class="logo"></image>
						<view class="center">
							<image :src="$IMG_URL('/static/test/memberlogo1.png')" mode="aspectFill" class="memberSize"></image>
						</view>
						<view :class="{
						  color1: item.state === 'effect',
						  color2: item.state === 'past',
						  color3: item.state == 'enabled'
						}">{{item.state_str}}</view>
					</view>
					<view class="bottom">
						<view class="title">
							{{item.title}}
						</view>
						<view class="size1 mb">
							有效期限：{{item.date_str}}
						</view>
						<view class="size1">
							添加日期：{{item.add_date}}
						</view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else
				:content="!activeIndex ?'已生效会员卡':activeIndex == 1 ?'使用中会员卡':activeIndex == 2 ?'已过期会员卡':'未启用会员卡'">
			</empty>
		</scroll-view>
	</view>
</template>

<script>
	import infomationVue from '../components/infomation.vue'
	import empty from '@/components/empty.vue'
	import {
		cardList
	} from '@/api/coach.js'
	export default {
		components: {
			infomationVue,
			empty
		},
		data() {
			return {
				status: 'loadmore',
				infomation: {
					user_id: '',
					form: 'all',
					page: 1
				},
				cardList: [{
					form: 'effect',

				}],
				activeIndex: 0,
				tabslist: [
					'全部',
					'使用中',
					'已过期',
					'未启用'
				],
				list: [],
				query: {}
			}
		},
		onLoad(e) {
			this.infomation.user_id = e.user_id
			this.getcardList()
		},
		methods: {
			scrolltolower(){
				this.infomation.page++
				this.getcardList()
			},
			getClass(state) {
				switch (state) {
					case 'past':
						return 'color1';
					case 'effect':
						return 'color2';
					default:
						return 'color3';
				}
			},
			getcardList() {
				cardList(this.infomation).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.query = res.data.user_info
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}
						console.log('list', this.list);
					}
				})
			},
			changeIndex(e) {
				if (this.activeIndex != e) {
					this.activeIndex = e
					if (!e) {
						this.infomation.form = 'all'
					} else if (e == 1) {
						this.infomation.form = 'effect'
					} else if (e == 2) {
						this.infomation.form = 'past'
					} else if (e == 3) {
						this.infomation.form = 'enabled'
					}
					this.query.page = 1
					this.list = []
					this.getcardList()
				}

			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.body {
		display: flex;
		flex-direction: column;
		align-items: center;

		.tabs {
			width: 750rpx;
			height: 88rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(199, 205, 179, 0.15);
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			padding-top: 25rpx;

			.Item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.size {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					text-align: center;
					color: #666666;
					margin-bottom: 12rpx;
				}

				.bar {
					width: 44rpx;
					height: 8rpx;
					border: 2rpx solid rgba(0, 0, 0, 0.00);
					border-radius: 2rpx;
				}
			}
		}

		.scroll-y {
			width: 100%;
			height: 90vh;

			.comlum_box {
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding-top: 24rpx;

				.Item {
					width: 702rpx;
					height: 280rpx;
					display: flex;
					flex-direction: column;
					background-image: url(https://ugeego.youjixiaoyang.com/static/member/memberbg.png);
					background-repeat: no-repeat no-repeat;
					background-size: cover;
					margin-bottom: 20rpx;

					.header {
						width: 100%;
						height: 90rpx;
						padding: 0 36rpx 0 36rpx;
						display: flex;
						flex-direction: row;
						align-items: center;

						.logo {
							width: 48rpx;
							height: 48rpx;
							margin-right: 12rpx;
						}

						.center {
							display: flex;
							flex-direction: row;
							align-items: center;
							flex: 1;

							.memberSize {
								width: 302rpx;
								height: 46rpx;
							}
						}

						.color1 {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: right;
							color: #48b0a9;
						}

						.color2 {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: right;
							color: #999999;
						}

						.color3 {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: right;
							color: #ee8e3a;
						}
					}

					.bottom {
						width: 100%;
						height: 190rpx;
						padding: 36rpx;
						display: flex;
						flex-direction: column;

						.title {
							opacity: 0.6;
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: left;
							color: #000000;
							margin-bottom: 12rpx;
						}

						.mb {
							margin-bottom: 12rpx;
						}

						.size1 {
							opacity: 0.4;
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC-Medium;
							font-weight: 500;
							text-align: left;
							color: #000000;
						}
					}
				}
			}
		}
	}
</style>